import React, { useMemo } from "react";
import EditPage, { createFields } from "../../Component/ResourceList/Edit";
import { LibAppView, utils } from '@/lib';
import { FormattedMessage } from "react-intl";
import dayjs from 'dayjs';

const CarouselEdit = LibAppView.withService({
})((props) => {
    const requireRules = useMemo(() => ([{ required: true, message: <FormattedMessage id="admin.pages.article.formItem.required"/>}]), []);

    const fields = useMemo(() =>createFields([{
        label: "标题",
        name: "title",
        type: "Input",
        required: true,
        rules: requireRules
    },{
        label: "模块",
        name: "module",
        type: "Input",
        required: true,
        rules: requireRules
    },{
        label: "图片",
        name: "image",
        type: "Upload"
    }, {
        label: "链接",
        name: "url",
        type: "Input"
    }, {
        label: "是否启用",
        name: "status",
        type: "Switch",
        props: {
            checkedChildren: "是",
            unCheckedChildren: "否"
        }
    }]),[]);
    return (
        <EditPage
            submitEndPoint="carousel.submit"
            fields={fields}
            initValues={{
                status: true
            }}
            buildRequest={(formData: any) => {
                return {
                    ...formData,
                    status: formData.status ? 1 : 0
                };
            }}
            buildResponse={(response: any) => {
                return {
                    ...response,
                    status: response.status === 1
                }
            }}
        />
    )
});

export default CarouselEdit;

